#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'arrow'
__explain__ = ''

import logging

from biliup.plugins.youtube import Youtube as YoutubeDownloader

logger = logging.getLogger('biliup')


YoutubeDownloader = YoutubeDownloader.__dict__.get("__wrapped__")


class CustomYoutubeDownloader(YoutubeDownloader):
    def __init__(self, fname, url, suffix='webm'):
        super().__init__(fname, url, suffix)

    def run(self):
        if not self.check_stream():
            return False
        self.fname = self.file_name
        retval = self.download(self.fname)
        logger.info(f'{retval}part: {self.fname}.{self.suffix}')
        self.rename(f'{self.fname}.{self.suffix}')
        return retval